package com.dundun.pattern.proxy;

public class Printer implements Printable {

    private String name;

    public Printer(String name) {
        this.name = name;
        heavyJob("正在生成Printer实例:" + name);
    }

    @Override
    public void setPrinterName(String name) {
        this.name = name;
    }

    @Override
    public String getPrinterName() {
        return name;
    }

    @Override
    public void print(String string) {
        System.out.println("[" + name + "]");
        System.out.println(string);
    }

    private void heavyJob(String msg) {
        System.out.print(msg);
        try {
            for(int i=0; i<5; ++i) {
                Thread.sleep(1000);
                System.out.print('.');
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("结束。");
    }
}
